Skip to main content

Full text of "Programming"

See other formats

Servos Unscrambled 


Make Projects 

build, hack, tweak, share, discover^ 

Servos Unscrambled 

Written By: Steven Robert Cypherd 


Servos bring life to our ideas. Servos can be mysterious, but in fact they are very simple. 
Servos use a simple electronic pulse to tell them what angle you want them to go to. It is 
electronic but not digital. There are digital servos and they are different than standard 
servos. Pulses are electronic, but they are part of our digital world. The abbreviation for 
microseconds is "us". The abbreviation for milliseconds is "ms". See pictures below. 

I am using a standard servo as an example. 

Servo inputs use pulses measured in microseconds (us) so that you have fine control over 
the angle you want the servo to go to. Microseconds are part of the language of 
microprocessors, not people. Functions that deal with microseconds do so in the way they 
were programmed. 

People get scrambled up because functions like pulsout do not work the way they think they 
should. Remember they are made for the system they are running on. Read your manual. 
Most pulsout functions are called like this: pulsout pin, time. Time is the number of 
microseconds in each unit that will make up the pulse, not an actual time or angle. See 
pictures below. 

Pulsout can be different on different processors in the same language because it is based on 
the clock speed of the processor. Also, it can be different in different versions of the same 
language. Read your manual. I think we should tell the companies to standardize functions 
like pulsout. It would make servos much more fun. 

Servos from their Radio Control heritage need a stream of pulses about every 20 
© Make Projects Page 1 of 2 

Servos Unscrambled 

milliseconds or so for about ten times of the same pulse to get them to recognize that it is 
the angle you want them to go to. In your program just set up a loop to send a train of pulses 
to the servo when you first set it to each new angle. After that you only need to re-fresh you 
servo about every 30-50 milliseconds or as needed by your servo. 

I make a constant of my time value like 28x2_TIME = 5. I state the maker, processor, speed 
and language version in a comment just so I know what I am using. This can be a nasty bug 
in a program to find. 

For reading sensors like the Sharp rangefinders you should not use a servo command that 
constantly updates the servo position every 20 microseconds or so. Why? Because the 
sensor needs time to calculate the distance reading and to update its output. The servo 
needs to be steady to do this. Once you get good data from the sensor then you can move 
the servo. Try it. Use the pulsout command to move the servo to the next scan point. Then 
give about 20-50 microseconds pause for the sensor to update its output and then read the 
sensor. You should get good data this way. Digital and analogue rangefinders use the same 
method for reading distance and only differ in how you read the device. 

See table below. 

Step 1 — Servos Unscrambled 


i*. clave tinaugh 

il pin. Ilmc 

': IT- " HI. I": ..I W*. 

3 ■ 3kS ■ IB not 3 

each iinH ■ Sua 
R*Jbd Yfiili Mftrtuftl! 

Fto training kaapa U» 

final* =in d atxiy -ip-nfl-H 

In LonlhrkLfoui rotation 
iflrwit *9G [prrnt, 
3D hjtli. ?SQ forward 

Uilfifl a standard 

«ir»Q ** an piampln 

Tim* = Angla In in 
tfrid«B by thi 


Tlmo = 1434.'S = 2B7 

puliBul pin, 397 
■ JIB dwgrwi (o * 

29V0l» Ktrvo 


rUn. fl « = High - L«w £^ MW ^,7J^Jj^ 

= 1 DDDUS i«i«. ■*, ..-n.i. ii aaaM 

SurvpR 3 n 9E > 1 JI V |d«d —I-"-™—**— ™*— ■ 

By »rva max mm la — miiBuw.*. 

100B MM o S.iiilK -r. mkriK^. 


■WRu-J (Km™**-) ■ 

■ IWOJM iflO^Jt^Wfl 



IT9I - rftTi - Isw ■ WW - lWQ - IPWwi 

ffjf>3* dMdad by hhyo mm onglt - 

i WW .■ 144 - 1.HH rnlcK+K««HM par *tg»a{l»d) 

SunMidi lar-y-i > Mmi ■ La- 
ps I E.H] t IDOD - 14-U.UliI a Efc» trc-JOTi 

TWrid - S*fvfl Artp* tfi m *MU bv hJ»u1 UHr 
Hm#- 14Ui't-l*70KB«Jt-unlk5] 


Urtlt = E-UH 

rWHIIIf P<r«, 99 ifr P«Ml*|y 5 ■ ID * 4SQ HDI !>D rir^rrns. |« A vrmn 

Timo = unit divided Into Hh hhvd an a le In ml-cf omcofldi. 

Tlltl*- - 1 SflO "nil - 3(1(1 |t aOCl hunrSr^rl pultt* "' SlJt tUCR 

Pul»ut pin. 30C vquflU a mjlav ?f 1 JOG mlcrpwK;<WHhi i<? tha pin. 
A larvo lo 9D tJagpaa*. 

■f " " II *fc ^"0WL rmt*tf*M 

CLUlftfrUj ., K-.^-.l 

IBM IK 1-H X* 

htdpn M H « 

Sht JH 149 tW 

f«¥ii *.«■*» 

..r.-r. ;(r^ i: -.t, 

•*■**+ *■' < u fr*i"q p*^, r*-«"+»>*] 'I ' i i ■ * 

lb rt ltd 

iw m- 4H 

r^irut tnti *ftpir*nl on 
ilfi i i m ppM#»Mf t bi ih* *fcifi* 

llHUigi bKIUH^K 

II b»l*d on IhH UML IpHKJ 

c«npinl» 1» ■!■■ ■ ■'■rel 

i,k,- r iv,»,. ;fl - 
mihen more dun. 

mt ii irilh'brtpnda 

r*. -» 4* **M *#*•+ *-r** u 

l'u!-.-;i'.H pin, Hrr 

tlm* l» units of us 
3 - J-x3 '13- not 3 
WJ rin^r..! ■> IS-OOui. 

1. 1. 1 . i ' [:i:i. villi if, « 
■tnrtdnrd «ftrirtj la 
$Q dosrava. 

• A servo using a standarc servo as an exampl. 

Servos are fun! 

This document was last generated on 2012-10-31 10:28:43 AM. 

© Make Projects 

Page 2 of 2